package com.beiming.libra.controller;

import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beiming.libra.common.page.PageResult;
import com.beiming.libra.domain.Role;
import com.beiming.libra.domain.dto.requestdto.CommonIdRequestDTO;
import com.beiming.libra.domain.dto.requestdto.RoleRequestDTO;
import com.beiming.libra.service.RoleService;
/**
 * 
 * @author weibo
 *
 */
@Controller
@Slf4j
@RequestMapping(value = "/role")
public class RoleController {

  private static final Logger LOGGER = LoggerFactory.getLogger(RoleController.class);
  @Resource
  private RoleService roleService;

  /**
   * 新增角色
   */
  @RequestMapping(value = "addRole", method = RequestMethod.POST)
  @ResponseBody
  public void addRole(@RequestBody @Valid RoleRequestDTO roleRequestDTO) {
    roleService.insertRole(roleRequestDTO);
  }

  /**
   * 获取角色信息
   */
  @RequestMapping(value = "getRole", method = RequestMethod.POST)
  @ResponseBody
  public Role getRole(@RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    return roleService.getRole(commonIdRequestDTO.getId());
  }

  /**
   * 获取角色信息列表
   */
  @RequestMapping(value = "listRole", method = RequestMethod.POST)
  @ResponseBody
  public PageResult<Role> listRole(@RequestBody RoleRequestDTO roleRequestDTO) {
    return roleService.listRole(roleRequestDTO);
  }

  /**
   * 更新角色信息
   */
  @RequestMapping(value = "updateRole", method = RequestMethod.POST)
  @ResponseBody
  public void updateRole(@RequestBody @Valid RoleRequestDTO roleRequestDTO) {
    roleService.updateRole(roleRequestDTO);
  }

  /**
   * 删除角色信息
   */
  @RequestMapping(value = "deleteRole", method = RequestMethod.POST)
  @ResponseBody
  public void deleteRole(@RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    roleService.deleteRole(commonIdRequestDTO.getId());
  }
}
